package controller

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"xs.jsjb/internal/app/menu/entity"
)

func (m *MenuController) GetMenu(c *gin.Context) {
	//定义参数
	var (
		params entity.GetMenuReq
		res    *entity.GetMenuRes
		err    error
	)
	//参数校验
	//参数解析
	if err := c.ShouldBind(&params); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 201,
			"msg":  "参数错误",
			"data": "",
		})
		return
	}
	//逻辑
	//逻辑代码里肯定得调用数据库,即service里调用repo里的增删改查具体代码
	//这个时候我们可以将repo抽象成接口作为service的参数,将service抽象成接口,作为controller的参数
	//接不接口的可以放一放,先把他变成参数
	res, err = m.service.GetMenu(c.Request.Context(), &params)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 202,
			"msg":  err,
			"data": "",
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "操作成功",
		"data": res,
	})
}
